package com.cws.frame;

import java.util.Properties;

import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

import com.cws.controller.business.ScenicController;
import com.cws.controller.business.SpotsController;
import com.cws.controller.sys.AuthController;
import com.cws.controller.sys.UserController;
import com.cws.model.Scenic;
import com.cws.model.Spots;
import com.cws.model.SysJob;
import com.cws.model.SysUser;
import com.cws.sys.Mem;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;

public final class AppInit {

	/**
	 * 调度器工厂
	 */
	private static SchedulerFactory sf = new StdSchedulerFactory();

	/**
	 * 初始化数据库表mapping
	 * @param arp
	 */
	public static void initArpMapping(ActiveRecordPlugin arp) {
		arp.addMapping("sysUser", "id", SysUser.class);
		arp.addMapping("sysJob", "id", SysJob.class);
		arp.addMapping("scenic", "id", Scenic.class);
		arp.addMapping("spots", "id", Spots.class);
	}

	/**
	 * 初始化系统所有controller路由
	 * @param r
	 */
	public static void initRoutes(Routes r) {
		r.add("/auth", AuthController.class);
		r.add("/user", UserController.class);
		r.add("/scenic", ScenicController.class);
		r.add("/spots", SpotsController.class);
	}

	public static SchedulerFactory getSchedulerFactory() {
		return sf;
	}

	public static void initConfig(Properties config) {
		Mem.setConfig(config);
	}

}
